package com.hdl.servlet.user;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.hdl.entity.HdlUser;
import com.hdl.entity.MallOrder;
import com.hdl.entity.MallOrderDetail;
import com.hdl.service.MallOrderService;
import com.hdl.service.OrderDetailService;
import com.hdl.service.impl.MallOrderServiceImpl;
import com.hdl.service.impl.OrderDetailServiceImpl;
import com.hdl.vo.DetailVO;

/**
 * OrderDetailServlet 查看用户的一个订单详情
 * @author Administrator
 *
 */
@WebServlet("/userorderlook.let")
public class OrderDetailServlet extends HttpServlet{

	private MallOrderService service = new MallOrderServiceImpl();
	private OrderDetailService os = new OrderDetailServiceImpl();
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		
		//获取参数
		HdlUser user = (HdlUser) req.getSession().getAttribute("user");
		String userId = user.getHdlUserId();
		String mallOrderId = req.getParameter("mallOrderId");
		
		//调用业务逻辑层方法  获取订单数据
		MallOrder order = service.selectById(mallOrderId);
		System.out.println(order);
		
		//调用业务逻辑层方法  获取订单详情数据
		List<DetailVO> list = os.findAllDetails(userId,mallOrderId);
		
		//存储数据
		req.setAttribute("vo", list);
		req.setAttribute("order", order);
		
		//请求转发
		req.getRequestDispatcher("/user/order-look.jsp").forward(req, resp);
		
	}
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doPost(req, resp);
	}
}
